package org.budo.support.java.awt.robot;

import java.awt.Color;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
import java.io.OutputStream;

/**
 * @author limingwei
 * 
 * @see BudoImageImpl
 * @see BudoSubImageImpl
 * @see net.sourceforge.tess4j.util.ImageHelper
 */
public interface BudoImage {
    public class AlphaPremultiplied extends BudoImageImpl {
        public AlphaPremultiplied(int width, int height) {
            super(alphaPremultiplied(width, height));
        }

        private static BufferedImage alphaPremultiplied(int width, int height) {
            ColorModel colorModel = ColorModel.getRGBdefault();
            WritableRaster writableRaster = colorModel.createCompatibleWritableRaster(width, height);
            return new BufferedImage(colorModel, writableRaster, colorModel.isAlphaPremultiplied(), null);
        }
    }

    int width();

    int height();

    int rgb(int x, int y);

    int rgbMax();

    int rgbMin();

    BudoImage orange();

    BudoImage pink();

    BudoImage color(Color color);

    BudoImage colorRandom();

    BudoImage copy();

    /**
     * 多次调用返回同一个
     */
    BudoGraphics graphics();

    BudoImage fillRect();

    BudoImage drawArc(int x, int y, int width, int height, int startAngle, int arcAngle);

    BudoImage drawRect(int x, int y, int w, int h);

    BudoImage drawRect(Rectangle rectangle);

    BudoImage drawString(String text, int x, int y);

    BudoImage drawString(String text);

    BudoImage drawCross(int x, int y);

    BudoImage colorRange(int x, int y, int w, int h);

    BudoImage drawImage(BudoImage image, int x, int y);

    BudoImage drawImage(Image image, int x, int y, int width, int height);

    /**
     * 截图
     */
    BudoImage subImage(Rectangle rectangle);

    BudoImage subImage(int x, int y, int w, int h);

    /**
     * 将图像纵向切条
     */
    BudoImage subImageVertical(int x, int w);

    BufferedImage getBufferedImage();

    /**
     * 转成png
     */
    byte[] toPng();

    byte[] toJpg();

    void toPng(OutputStream outputStream);

    void toJpg(OutputStream outputStream);
}